#include <vendor/mega/hardware/common/mega_camera_enhancement/server/1.0/IWmarkServer.h>
#include <hidl/Status.h>
#include <utils/misc.h>
#include <hidl/HidlSupport.h>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include "PngTools.h"

using namespace std;

using ::android::sp;
using ::android::hardware::hidl_string;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::BackgroundColor;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::IWmarkServer;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::WmarkPicture;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::WmarkText;

using android::sp;
using std::string;

int sendPngMsg(sp<IWmarkServer> service, uint8_t *buf, int w, int h, int ch, int x, int y, int index, int enable)
{

    WmarkPicture png;

    png.w = w;
    png.h = h;
    png.ch = ch;
    png.locate.x = x;
    png.locate.y = y;
    png.locate.index = index;
    png.locate.enable = enable;
    png.locate.faceId[0] = 2;
    png.locate.faceId[1] = 3;
    png.locate.faceId[2] = 4;
    png.locate.faceId[3] = 5;

    memcpy(&png.data[0], buf, w * h * ch);

    service->updatePicture(png);

    return 0;
}

int main(int argc, char **argv)
{
    sp<IWmarkServer> service = IWmarkServer::getService();
    if (service == nullptr)
    {
        printf("Failed to get service\n");
        return -1;
    }

    android::pic_data out;
    if (argc == 2)
    {
        android::decode_png(argv[1], &out);
        // write_png_file(argv[2], &out);

        if (out.width * out.height * out.channel >=819200) {
            printf("目标水印 图片大于 800kb error     info=%dx%dx%d!\n", out.width ,out.height ,out.channel);
            free(out.rgba);
            return -1;
        }
        sendPngMsg(service, out.rgba, out.width, out.height, out.channel, 0, 0, 0, 1);
        free(out.rgba);
    }
    else
    {
        puts("please input src file, \nargv[1]:source.png ");
    }

    printf("init.\n");
    return 0;
}